import os

from fastapi import FastAPI
from langchain_openai import AzureChatOpenAI
from langchain_core.messages import SystemMessage, HumanMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langserve import add_routes
from src.ai.langchain.init_ds_llm import get_ds_llm

os.environ["http_proxy"] = "127.0.0.1:7890"
os.environ["https_proxy"] = "127.0.0.1:7890"
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "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"

# os.environ["AZURE_OPENAI_ENDPOINT"] = "http://menshen.test.xdf.cn"
# os.environ["OPENAI_API_KEY"] = "c8575027653b42b1b47747f0b4ab135b"
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_VERSION"] = "2023-05-15"

llm = get_ds_llm()

prompt = ChatPromptTemplate.from_messages([
    ("system", "你一个出色的翻译员，把下面的内容翻译成{language}"),
    ("human", "{text}")
])

parser = StrOutputParser()

#  prompt模板链式调用
chain = prompt | llm | parser

# 提示词模板方式
print(chain.invoke({"language": "英语", "text": "昨晚你看电视了么?"}))

# 普通方式链式调用
# chain = llm | parser

# 普通方式
# print(chain.invoke("解释一下python里面tuple的用法"))
